package com.thinkwide.data.exchange;

import com.thinkwide.data.ormapping.datatable.MFDataColumn;
import com.thinkwide.data.ormapping.datatable.MFDataRow;
import com.thinkwide.data.ormapping.datatable.MFDataTable;
import com.thinkwide.data.core.MFStringBuilder;

public class MFSimpleHtml {
    public static String getHtmlTable(MFDataTable dataTable) {
        MFStringBuilder out = new MFStringBuilder();
        int width = dataTable.getColumns().count() * 150;
        out.println("<table class='xtable' width='" + width + "' border='1'>");
        out.println("<tr class='trHead' >");

        for (MFDataColumn item : dataTable.getColumns()) {

            out.println("<td>" + item.getTitle() + "</td>");
        }
        out.println("</tr>");

        for (MFDataRow row : dataTable.getRows()) {
            int i = 0;
            out.println("<tr>");
            for (MFDataColumn col : dataTable.getColumns()) {
                String data = row.getString(i);
                out.println("<td>" + data + "</td>");
                i++;
            }
            out.println("</tr>");

        }
        out.println("</table>");

        return out.toString();
    }
}
